|
|
|
|
|
|
|
blnOK = False
txtUpper.SetFocus
End If
'
' check the combined field
If Len(Trim(txtCombined)) = 0 Then
MsgBox "Combined field is a required field"
blnOK = False
txtCombined.SetFocus
End If
'
' set if all passed
If blnOK = True Then
Unload Me
End If
'
End Sub |
|
|
|
|
|
|
|
|
The only change you made is to check the length of the string in the txtCombined textbox. If the result is zero, an error message is displayed. Notice the use of the Trim function to remove any trailing or leading spaces from the txtCombined string. This makes sure that users who enter blank spaces into the field do not get past the validation step. |
|
|
|
|
|
|
|
|
There are times when entering a value in one field of the form means that other fields on the form must also contain valid data. Fields of this type are called conditional fields. A good example of conditional field validation can be found in an order tracking system. For example, when a user enters Yes in the Ship to Site? field, he or she must then enter a valid value in the Shipping Address field. The Shipping Address field is a conditional field because its validation is based on the condition of the Ship to Site? field. |
|
|
|
|
|
|
|
|
Now add a conditional validation to the project. Make the field CustType conditional to the field Upper. In other words, if the Upper field contains data, the CustType field must contain data. See Listing 5.9 for an example of how to do this. |
|
|
|
|
|
|
|
|
Listing 5.9. The form-level conditional validation routine. |
|
|
|
|
|
|
|
|
Private Sub cmdOK_Click()
'
Dim intHigh As Integer
Dim intLow As Integer
Dim strHighLowMsg As String
' |
|
|
|
|
|